package com.irdstudio.cdp.pboc.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.cdp.pboc.service.dao.PbocLoadBasicDao;
import com.irdstudio.cdp.pboc.service.domain.PbocLoadBasic;
import com.irdstudio.cdp.pboc.service.facade.PbocLoadBasicService;
import com.irdstudio.cdp.pboc.service.vo.PbocLoadBasicVO;
import com.irdstudio.basic.framework.core.base.FrameworkService;
/**
 * <p>ServiceImpl: 贷款基本信息				<p>
 * @author ligm
 * @date 2018-12-27
 */
@Service("pbocLoadBasicService")
public class PbocLoadBasicServiceImpl implements PbocLoadBasicService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(PbocLoadBasicServiceImpl.class);

	@Autowired
	private PbocLoadBasicDao pbocLoadBasicDao;
	
	/**
	 * 新增操作
	 */
	public int insertPbocLoadBasic(PbocLoadBasicVO inPbocLoadBasicVo)  throws Exception {
		logger.debug("当前新增数据为:"+ inPbocLoadBasicVo.toString());
		int num = 0;
		try {
			PbocLoadBasic pbocLoadBasic = new PbocLoadBasic();
			beanCopy(inPbocLoadBasicVo, pbocLoadBasic);
			num = pbocLoadBasicDao.insertPbocLoadBasic(pbocLoadBasic);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(PbocLoadBasicVO inPbocLoadBasicVo)  throws Exception {
		logger.debug("当前删除数据条件为:"+ inPbocLoadBasicVo);
		int num = 0;
		try {
			PbocLoadBasic pbocLoadBasic = new PbocLoadBasic();
			beanCopy(inPbocLoadBasicVo, pbocLoadBasic);
			num = pbocLoadBasicDao.deleteByPk(pbocLoadBasic);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocLoadBasicVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(PbocLoadBasicVO inPbocLoadBasicVo)  throws Exception {
		logger.debug("当前修改数据为:"+ inPbocLoadBasicVo.toString());
		int num = 0;
		try {
			PbocLoadBasic pbocLoadBasic = new PbocLoadBasic();
			beanCopy(inPbocLoadBasicVo, pbocLoadBasic);
			num = pbocLoadBasicDao.updateByPk(pbocLoadBasic);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocLoadBasicVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public PbocLoadBasicVO queryByPk(PbocLoadBasicVO inPbocLoadBasicVo) {
		
		logger.debug("当前查询参数信息为:"+ inPbocLoadBasicVo);
		try {
			PbocLoadBasic queryPbocLoadBasic = new PbocLoadBasic();
			beanCopy(inPbocLoadBasicVo, queryPbocLoadBasic);
			PbocLoadBasic queryRslPbocLoadBasic = pbocLoadBasicDao.queryByPk(queryPbocLoadBasic);
			if (Objects.nonNull(queryRslPbocLoadBasic)) {
				PbocLoadBasicVO outPbocLoadBasicVo = beanCopy(queryRslPbocLoadBasic, new PbocLoadBasicVO());
				logger.debug("当前查询结果为:"+ outPbocLoadBasicVo.toString());
				return outPbocLoadBasicVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
			throw e;
		}
		return null;
	}
	
	/**
	 * 需求编号:2019D0519
	 * 问题编号:2019D0519
	 * 开发人员: caoxin
	 * 创建日期:2019/7/19
	 * 功能描述:通过reportId查询贷款信息
	 * 修改日期:2019/7/19
	 * 修改描述:
	 */
	@SuppressWarnings("unchecked")
	public List<PbocLoadBasicVO> selectByReportId(PbocLoadBasicVO inPbocLoadBasicVo) throws Exception {
		List<PbocLoadBasicVO> vos = null;
		logger.debug("当前查询参数信息为:"+ inPbocLoadBasicVo);
		try {
			PbocLoadBasic queryPbocLoadBasic = new PbocLoadBasic();
			beanCopy(inPbocLoadBasicVo, queryPbocLoadBasic);
			List<PbocLoadBasic> queryRslPbocLoadBasic = pbocLoadBasicDao.selectByReportId(queryPbocLoadBasic);
			vos = (List<PbocLoadBasicVO>) beansCopy(queryRslPbocLoadBasic, PbocLoadBasicVO.class);
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
			throw e;
		}
		return vos;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocLoadBasicVO> queryAllOwner(PbocLoadBasicVO pbocLoadBasicVo)  throws Exception {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<PbocLoadBasicVO> list = null;
		try {
			List<PbocLoadBasic> pbocLoadBasics = pbocLoadBasicDao.queryAllOwnerByPage(pbocLoadBasicVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pbocLoadBasics.size());
			pageSet(pbocLoadBasics, pbocLoadBasicVo);
			list = (List<PbocLoadBasicVO>) beansCopy(pbocLoadBasics, PbocLoadBasicVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocLoadBasicVO> queryAllCurrOrg(PbocLoadBasicVO pbocLoadBasicVo)  throws Exception {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<PbocLoadBasic> pbocLoadBasics = pbocLoadBasicDao.queryAllCurrOrgByPage(pbocLoadBasicVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+pbocLoadBasics.size());
		List<PbocLoadBasicVO> list = null;
		try {
			pageSet(pbocLoadBasics, pbocLoadBasicVo);
			list = (List<PbocLoadBasicVO>) beansCopy(pbocLoadBasics, PbocLoadBasicVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocLoadBasicVO> queryAllCurrDownOrg(PbocLoadBasicVO pbocLoadBasicVo)  throws Exception {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<PbocLoadBasic> pbocLoadBasics = pbocLoadBasicDao.queryAllCurrDownOrgByPage(pbocLoadBasicVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ pbocLoadBasics.size());
		List<PbocLoadBasicVO> list = null;
		try {
			pageSet(pbocLoadBasics, pbocLoadBasicVo);
			list = (List<PbocLoadBasicVO>) beansCopy(pbocLoadBasics, PbocLoadBasicVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}
//	@Override
//	public List<PbocLoadBasicVO> selectReportId(PbocLoadBasicVO pbocLoadBasicVo) {
//		logger.debug("当前查询参数信息为:"+ pbocLoadBasicVo);
//		List<PbocLoadBasicVO> list = null;
//		try {
//			List<PbocLoadBasicVO> pbocCreditStatus = pbocLoadBasicDao.selectReportId(pbocLoadBasicVo);
//			list = (List<PbocLoadBasicVO>) beansCopy(pbocCreditStatus, PbocLoadBasicVO.class);
//		} catch (Exception e) {
//			logger.error("查询数据发生异常!", e);
//		}
//		return list;
//	}
//	
//	/**
//	 * 
//	 * TODO 根据报告编号查询余额<br>
//	 * @author wanglihua
//	 * @since 2019年5月8日 下午4:59:00
//	 * @date 2019年5月8日 下午4:59:00
//	 * @version 0.1 
//	 */
//	@SuppressWarnings("unchecked")
//	@Override
//	public List<PbocLoadBasicVO> queryByFId(String fId) {
//		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
//		List<PbocLoadBasic> pbocLoadBasics = pbocLoadBasicDao.queryByFId(fId);
//		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ pbocLoadBasics.size());
//		List<PbocLoadBasicVO> list = null;
//		try {
//			list = (List<PbocLoadBasicVO>) beansCopy(pbocLoadBasics, PbocLoadBasicVO.class);
//		} catch (Exception e) {
//			logger.error("数据转换出现异常!", e);
//		}
//		
//		return list;
//	}
}
